
package provide apple_events 0.1

package require pdwindow
package require wheredoesthisgo

namespace import ::pdwindow::pdtk_post

# from http://wiki.tcl.tk/12987

set ::tk::mac::CGAntialiasLimit 0 ;# min line thickness to anti-alias (default: 3)
set ::tk::mac::antialiasedtext  1 ;# enable/disable anti-aliased text

# kAEOpenDocuments
proc ::tk::mac::OpenDocument {args} {
    foreach filename $args { 
        open_file $filename
    }
    set ::pd_menucommands::menu_open_dir [file dirname $filename]
}

# kEventAppHidden
proc ::tk::mac::OnHide {args} {
    # TODO
    pdtk_post "::tk::mac::OnHide $args ++++++++++++++++++++++++++++++"
}

# kEventAppShown
proc ::tk::mac::OnShow {args} {
    # TODO
    pdtk_post "::tk::mac::OnShow $args ++++++++++++++++++++++++++++++"
}

# kAEShowPreferences
proc ::tk::mac::ShowPreferences {args} {
    pdtk_post "::tk::mac::ShowPreferences $args ++++++++++++++++++++"
    pdsend "pd start-path-dialog"
}

# kAEQuitApplication
proc ::tk::mac::Quit {args} {
    # TODO sort this out... how to quit pd-gui after sending the message
    pdtk_post "::tk::mac::Quit $args ++++++++++++++++++++"
    pdsend "pd verifyquit"
}

# these I gleaned by reading the source (tkMacOSXHLEvents.c)
proc ::tk::mac::PrintDocument {args} {
    # TODO what's $mytoplevel here?.  I am guessing args would be the same as
    # ::tk::mac::OpenDocument
    #menu_print $mytoplevel
    pdtk_post "::tk::mac::PrintDocument $args"
}

proc ::tk::mac::OpenApplication {args} {
    pdtk_post "::tk::mac::OpenApplication $args ++++++++++++++++++++"
}

proc ::tk::mac::ReopenApplication {args} {
    pdtk_post "::tk::mac::ReopenApplication $args ++++++++++++++++++++"
}
